From b52421dedd45fc035a2993d10ea90c878cd77453 Mon Sep 17 00:00:00 2001 From: David Barratt Date: Wed, 15 Nov 2017 13:02:24 -0500 Subject: [PATCH] Prevent new users from being sent emails This change prevents users who have no logged actions from recieving emails from people. Bug: T178842 Change-Id: Iedd5f082368a395766cb29ded6dad17a288bf511 --- includes/DefaultSettings.php | 1 + includes/specials/SpecialEmailuser.php | 36 +++++++++++++++++++++++--- includes/user/User.php | 1 + languages/i18n/en.json | 1 + languages/i18n/qqq.json | 1 + 5 files changed, 37 insertions(+), 3 deletions(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 3cd7ef181a..06c9ffb08c 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -5166,6 +5166,7 @@ $wgGroupPermissions['user']['sendemail'] = true; $wgGroupPermissions['user']['applychangetags'] = true; $wgGroupPermissions['user']['changetags'] = true; $wgGroupPermissions['user']['editcontentmodel'] = true; +$wgGroupPermissions['user']['sendemail-new-users'] = true; // Implicit group for accounts that pass $wgAutoConfirmAge $wgGroupPermissions['autoconfirmed']['autoconfirmed'] = true; diff --git a/includes/specials/SpecialEmailuser.php b/includes/specials/SpecialEmailuser.php index 30eb38d04a..d57ba09465 100644 --- a/includes/specials/SpecialEmailuser.php +++ b/includes/specials/SpecialEmailuser.php @@ -224,15 +224,45 @@ class SpecialEmailUser extends UnlistedSpecialPage { wfDebug( "Target is invalid user.\n" ); return 'notarget'; - } elseif ( !$target->isEmailConfirmed() ) { + } + + if ( !$target->isEmailConfirmed() ) { wfDebug( "User has no valid email.\n" ); return 'noemail'; - } elseif ( !$target->canReceiveEmail() ) { + } + + if ( !$target->canReceiveEmail() ) { wfDebug( "User does not allow user emails.\n" ); return 'nowikiemail'; - } elseif ( $sender !== null ) { + } + + if ( + $target->getEditCount() === 0 + && ( $sender === null || !$sender->isAllowed( 'sendemail-new-users' ) ) + ) { + // Determine if target has any other logged actions. + $dbr = wfGetDB( DB_REPLICA ); + $log_id = $dbr->selectField( + 'logging', + 'log_id', + [ + 'log_user' => $target->getId(), + "NOT (log_type = 'newusers' AND log_action = 'autocreate')", + ], + __METHOD__, + [ 'LIMIT' => 1 ] + ); + + if ( !$log_id ) { + wfDebug( "User has no logged actions on this wiki.\n" ); + + return 'nowikiemail'; + } + } + + if ( $sender !== null ) { $blacklist = $target->getOption( 'email-blacklist', [] ); if ( $blacklist ) { $lookup = CentralIdLookup::factory(); diff --git a/includes/user/User.php b/includes/user/User.php index 854ebbd37d..f31d61bb19 100644 --- a/includes/user/User.php +++ b/includes/user/User.php @@ -178,6 +178,7 @@ class User implements IDBAccessObject { 'reupload-shared', 'rollback', 'sendemail', + 'sendemail-new-users', 'siteadmin', 'suppressionlog', 'suppressredirect', diff --git a/languages/i18n/en.json b/languages/i18n/en.json index 5083bedae8..767c0a6dcb 100644 --- a/languages/i18n/en.json +++ b/languages/i18n/en.json @@ -1237,6 +1237,7 @@ "right-siteadmin": "Lock and unlock the database", "right-override-export-depth": "Export pages including linked pages up to a depth of 5", "right-sendemail": "Send email to other users", + "right-sendemail-new-users": "Send email to users with no logged actions", "right-managechangetags": "Create and (de)activate [[Special:Tags|tags]]", "right-applychangetags": "Apply [[Special:Tags|tags]] along with one's changes", "right-changetags": "Add and remove arbitrary [[Special:Tags|tags]] on individual revisions and log entries", diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json index 862f64cc9c..7b5b3c22b1 100644 --- a/languages/i18n/qqq.json +++ b/languages/i18n/qqq.json @@ -1431,6 +1431,7 @@ "right-siteadmin": "{{doc-right|siteadmin}}", "right-override-export-depth": "{{doc-right|override-export-depth}}", "right-sendemail": "{{doc-right|sendemail}}", + "right-sendemail-new-users": "{{doc-right|sendemail-new-users}}", "right-managechangetags": "{{doc-right|managechangetags}}", "right-applychangetags": "{{doc-right|applychangetags}}", "right-changetags": "{{doc-right|changetags}}", -- 2.20.1